
@{
    ViewData["Title"] = "调拨管理";
}
<style type="text/css">
    form {
        margin: 0;
    }

    textarea {
        display: block;
    }

    .need {
        FONT-STYLE: normal;
        FONT-FAMILY: 微软雅黑;
        FONT-SIZE: 13px;
        TEXT-DECORATION: none;
        width: 75px;
    }

    .auto-style1 {
        height: 25px;
    }
</style>
<div class="mini-toolbar" style="border-bottom:0;padding:0px;padding-left:10px;" id="searchForm">
    <table>
        <tr>
            <td class="need">调拨单号:</td>
            <td>
                <input id="who_code" name="who_code" class="mini-textbox" />
            </td>
            <td class="need">调拨状态:</td>
            <td>
                <input class="mini-combobox" id="who_status" name="who_status" textField="name" valueField="id" data="[{id:'0',name:'保存'},{id:'1',name:'调出途中-提交'},{id:'2',name:'调入确认'},{id:'3',name:'核准'}]" showNullItem="true" nullitemtext="请选择..." />
            </td>
            <td class="need">调入时间:</td>
            <td>
                <input id="who_in_timeS" name="who_in_timeS" class="mini-datepicker" />-<input id="who_in_timeE" name="who_in_timeE" class="mini-datepicker" />
            </td>

            @if (Html.CheckPermission("Wh.Order.Index.AllWarehouse")){
                <td><a class="mini-button" style="width:120px;" iconcls="icon-search" onclick="OnSearch()">查询</a></td>
            }
            else{
                <td><a class="mini-button" style="width:120px;" iconcls="icon-search" onclick="onSearch()">查询</a></td>
            }
        </tr>
        <tr>
            <td class="need">调出仓库:</td>
            <td>
                @*<input id="wh_id_out" name="wh_id_out" class="mini-combobox" textfield="wh_name" valuefield="wh_id" shownullitem="true" allowinput="true" nullitemtext="请选择..." valueFromSelect="true" url="/wh/Order/GetWarehouse" />*@
                <input id="wh_id_out" name="wh_id_out" class="mini-buttonedit" onbuttonclick="onButtonEditOut" />
            </td>
            <td class="need">调入仓库:</td>
            <td>
                @*<input id="wh_id_in" name="wh_id_in" class="mini-combobox" textfield="wh_name" valuefield="wh_id" shownullitem="true" allowinput="true" nullitemtext="请选择..." valueFromSelect="true" url="/wh/Order/GetWarehouse" />*@
                <input id="wh_id_in" name="wh_id_in" class="mini-buttonedit" onbuttonclick="onButtonEditIn" />
            </td>
            <td class="need">调出时间:</td>
            <td>
                <input id="who_out_timeS" name="who_out_timeS" class="mini-datepicker" />-<input id="who_out_timeE" name="who_out_timeE" class="mini-datepicker" />
            </td>
            <td><a class="mini-button" style="width:120px;" iconcls="icon-add" onclick="Add()">新增</a></td>
        </tr>
    </table>
</div>
<div class="mini-fit">
    <div id="datagrid1" class="mini-datagrid" style="width:100%;height:100%;" sortmode="client" idField="whaCode" sizeList="[10,20,50]" allowResize="true" url="/wh/Order/Indexajax" onrowdblclick="rowdblclick"> 
        <div property="columns">
            <div field="who_code" allowSort="true" width="120" headerAlign="center" align="center">
                调拨单号
            </div>
            <div field="who_out_time" allowSort="true" width="120" headerAlign="center" dateFormat="yyyy-MM-dd" align="center">
                调出时间
            </div>
            <div field="who_in_time" allowSort="true" width="120" headerAlign="center" dateFormat="yyyy-MM-dd" align="center">
                调入时间
            </div>
            <div field="wh_name_out" allowSort="true" width="120" headerAlign="center" align="center">
                调出仓库
            </div>
            <div field="wh_name_in" allowSort="true" width="120" headerAlign="center" align="center">
                调入仓库
            </div>
            <div field="who_status" allowSort="true" width="120" headerAlign="center" align="center">
                调拨状态
            </div>
        </div>
    </div>
</div>
<div id="win" class="mini-window" title="选择" style="width:630px;height:450px;"
     showMaxButton="true" showToolbar="true" showFooter="true" showModal="false" allowResize="true" allowDrag="true">
    <div property="toolbar" style="padding:5px;" id="divSearch2">
        <table>
            <tr>
                <td><input class="mini-hidden" id="win_wh_id" /></td>
                <td><label for="name">仓库名称:</label></td>
                <td><input class="mini-textbox" id="wh_name" name="wh_name" /></td>
                <td><label for="name">组织名称:</label></td>
                <td><input class="mini-textbox" id="org_name" name="org_name" /></td>
                <td> <a plain="true" class="mini-button" iconcls="icon-search" onclick="doSearch">查找</a></td>
                <td> <a plain="true" class="mini-button" iconcls="icon-ok" onclick="Insert">选入</a></td>
            </tr>
        </table>
    </div>
    <div class="mini-fit">
        <div id="datagrid2" class="mini-datagrid" url="/wh/Order/GetWarehouse"
             allowResize="true" pageSize="20" multiSelect="true" idField="wh_id" style="width:100%;height:100%;" onrowdblclick="onRowdblClick">
            <div property="columns">
                <div type="indexcolumn" width="10"></div>
                <div field="wh_name" width="60" headerAlign="center" align="center">仓库名称</div>
                <div field="org_name" width="60" headerAlign="center" align="center">组织名称</div>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">
    mini.parse();
    var grid = mini.get("datagrid1");

    function onSearch() {

        var wh_id_out = mini.get("wh_id_out").getValue();
        var wh_id_in = mini.get("wh_id_in").getValue();
        if (!wh_id_in && !wh_id_out) {
            sx.error("调出仓库和调入仓库 两者中必须有一个等于该账号所属仓库!");
            return;
        }
        $.ajax({
            type: "post",
            url: "/wh/Order/checkwarehouse",
            data: { wh_id_out: wh_id_out, wh_id_in: wh_id_in },
            dataType: "json",
            success: function (data) {
                if (data.resultCode == sx.resultCode.ok) {
                    var form = new mini.Form("#searchForm");
                    var data1 = form.getData();
                    if (data.info == "0") {
                        data1.belongIn = 0;
                    }
                    else {
                        data1.belongIn = 1;
                    }
                    grid.load(data1);
                }
                else {
                    sx.error(data.info);
                }
            }
        });
        
    }

    function OnSearch() { 
        var form = new mini.Form("#searchForm");
        var data = form.getData();
        grid.load(data);
    }

    function rowdblclick(e) { 
        var record = e.record;
        parent.addTab("调拨单明细", "/wh/Order/edit?id=" + record.who_id); 
    }

    function Add() {
        parent.addTab("调拨单", "/wh/Order/edit");
    }

    function doSearch() {
        var form = new mini.Form("#divSearch2");
        var data = form.getData();
        mini.get("datagrid2").load(data);
    }
    
    function onButtonEditIn(e) {
        mini.get("win").show();
        mini.get("win_wh_id").setValue("wh_id_in");
        //mini.get("datagrid2").setUrl("/wh/Order/GetWarehouseByUserIn");
        //mini.get("datagrid2").clearRows();
    }

    function onButtonEditOut(e) {
        mini.get("win").show();
        mini.get("win_wh_id").setValue("wh_id_out");
        //mini.get("datagrid2").setUrl("/wh/Order/GetWarehouseByUserOut");
        //mini.get("datagrid2").clearRows();
    }

    function Insert() {
        var select = mini.get("datagrid2").getSelected();
        var wh_id = mini.get("win_wh_id").getValue();
        if (select) {
            mini.get(wh_id).setValue(select.wh_id);
            mini.get(wh_id).setText(select.wh_name);
            mini.get("win").hide();
        }
        else {
            sx.error("请选择仓库!");
        }
    }

    function onRowdblClick(e) {
        Insert();
    }
</script>